home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
WINSRC20.ZIP
/
LORENZ.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-18
|
46KB
|
1,713 lines
/*
This file contains two 3 dimensional orbit-type fractal
generators - IFS and LORENZ3D, along with code to generate
red/blue 3D images. Tim Wegner
*/
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include "fractint.h"
#include "fractype.h"
struct affine
{
/* weird order so a,b,e and c,d,f are vectors */
double a;
double b;
double e;
double c;
double d;
double f;
};
/* Routines in this module */
int orbit3dlongsetup();
int orbit3dfloatsetup();
int lorenz3dlongorbit(long *, long *, long *);
int lorenz3dfloatorbit(double *, double *, double *);
int henonfloatorbit(double *, double *, double *);
int henonlongorbit(long *, long *, long *);
int rosslerfloatorbit(double *, double *, double *);
int pickoverfloatorbit(double *, double *, double *);
int gingerbreadfloatorbit(double *, double *, double *);
int rosslerlongorbit(long *, long *, long *);
int kamtorusfloatorbit(double *, double *, double *);
int kamtoruslongorbit(long *, long *, long *);
int orbit2dfloat(void);
int orbit2dlong(void);
int orbit3dlongcalc(void);
int orbit3dfloatcalc(void);
int funny_glasses_call(int (*calc)());
int ifs(void);
int orbit3dfloat(void);
int orbit3dlong(void);
int ifs3d(void);
static int ifs3dlong(void);
static int ifs3dfloat(void);
static double determinant(double mat[3][3]);
static int solve3x3(double mat[3][3],double vec[3],double ans[3]);
static int setup_convert_to_screen(struct affine *);
static void setupmatrix(MATRIX);
int realtime;
extern int overflow;
extern int soundflag;
extern int basehertz;
extern int fractype;
extern int glassestype;
extern int whichimage;
extern int init3d[];
extern char floatflag;
extern VECTOR view;
extern int xxadjust, yyadjust;
extern int xxadjust1, yyadjust1;
extern int xshift,yshift;
extern int xshift1,yshift1;
extern void (*plot)();
extern void (*standardplot)();
extern int debugflag; /* for debugging purposes */
extern int xdots, ydots; /* coordinates of dots on the screen */
extern int maxit; /* try this many iterations */
extern double param[];
extern double xxmin,xxmax,yymin,yymax,xx3rd,yy3rd; /* selected screen corners */
extern int diskvideo; /* for disk-video klooges */
extern int bitshift; /* bit shift for fudge */
extern long fudge; /* fudge factor (2**n) */
extern int colors; /* maximum colors available */
extern int display3d;
static int t;
static long l_dx,l_dy,l_dz,l_dt,l_a,l_b,l_c,l_d;
static long l_adt,l_bdt,l_cdt,l_xdt,l_ydt;
static long l_initx,l_inity,l_initz;
static long initorbitlong[3];
static double dx,dy,dz,dt,a,b,c,d;
static double adt,bdt,cdt,xdt,ydt;
static double initx,inity,initz;
static double initorbit[3];
extern int inside;
extern int alloc_resume(int,int);
extern int start_resume();
extern void end_resume();
extern int put_resume(int len, ...);
extern int get_resume(int len, ...);
extern int calc_status, resuming;
/* these are potential user parameters */
int connect = 1; /* flag to connect points with a line */
int waste = 100; /* waste this many points before plotting */
int projection = 2; /* projection plane - default is to plot x-y */
extern int active_system;
/******************************************************************/
/* zoom box conversion functions */
/******************************************************************/
static double determinant(mat) /* determinant of 3x3 matrix */
double mat[3][3];
{
/* calculate determinant of 3x3 matrix */
return(mat[0][0]*mat[1][1]*mat[2][2] +
mat[0][2]*mat[1][0]*mat[2][1] +
mat[0][1]*mat[1][2]*mat[2][0] -
mat[2][0]*mat[1][1]*mat[0][2] -
mat[1][0]*mat[0][1]*mat[2][2] -
mat[0][0]*mat[1][2]*mat[2][1]);
}
static int solve3x3(mat,vec,ans) /* solve 3x3 inhomogeneous linear equations */
double mat[3][3], vec[3], ans[3];
{
/* solve 3x3 linear equation [mat][ans] = [vec] */
double denom;
double tmp[3][3];
int i;
denom = determinant(mat);
if(fabs(denom) < DBL_EPSILON) /* test if can solve */
return(-1);
memcpy(tmp,mat,sizeof(double)*9);
for(i=0;i<3;i++)
{
tmp[0][i] = vec[0];
tmp[1][i] = vec[1];
tmp[2][i] = vec[2];
ans[i] = determinant(tmp)/denom;
tmp[0][i] = mat[0][i];
tmp[1][i] = mat[1][i];
tmp[2][i] = mat[2][i];
}
return(0);
}
/* Conversion of complex plane to screen coordinates for rotating zoom box.
Assume there is an affine transformation mapping complex zoom parallelogram
to rectangular screen. We know this map must map parallelogram corners to
screen corners, so we have following equations:
a*xxmin+b*yymax+e == 0 (upper left)
c*xxmin+d*yymax+f == 0
a*xx3rd+b*yy3rd+e == 0 (lower left)
c*xx3rd+d*yy3rd+f == ydots-1
a*xxmax+b*yymin+e == xdots-1 (lower right)
c*xxmax+d*yymin+f == ydots-1
First we must solve for a,b,c,d,e,f - (which we do once per image),
then we just apply the transformation to each orbit value.
*/
static int setup_convert_to_screen(struct affine *scrn_cnvt)
{
/* we do this twice - rather than having six equations with six unknowns,
everything partitions to two sets of three equations with three
unknowns. Nice, because who wants to calculate a 6x6 determinant??
*/
double mat[3][3];
double vec[3];
/*
first these equations - solve for a,b,e
a*xxmin+b*yymax+e == 0 (upper left)
a*xx3rd+b*yy3rd+e == 0 (lower left)
a*xxmax+b*yymin+e == xdots-1 (lower right)
*/
mat[0][0] = xxmin;
mat[0][1] = yymax;
mat[0][2] = 1.0;
mat[1][0] = xx3rd;
mat[1][1] = yy3rd;
mat[1][2] = 1.0;
mat[2][0] = xxmax;
mat[2][1] = yymin;
mat[2][2] = 1.0;
vec[0] = 0.0;
vec[1] = 0.0;
vec[2] = (double)(xdots-1);
if(solve3x3(mat,vec, &(scrn_cnvt->a)))
return(-1);
/*
now solve these:
c*xxmin+d*yymax+f == 0
c*xx3rd+d*yy3rd+f == ydots-1
c*xxmax+d*yymin+f == ydots-1
(mat[][] has not changed - only vec[])
*/
vec[0] = 0.0;
vec[1] = (double)(ydots-1);
vec[2] = (double)(ydots-1);
if(solve3x3(mat,vec, &scrn_cnvt->c))
return(-1);
return(0);
}
/******************************************************************/
/* setup functions - put in fractalspecific[fractype].per_image */
/******************************************************************/
double orbit;
long l_orbit;
extern double sinx,cosx;
long l_sinx,l_cosx;
int orbit3dlongsetup()
{
connect = 1;
waste = 100;
projection = 2;
if(fractype==LHENON || fractype==KAM || fractype==KAM3D)
connect=0;
if(fractype==LROSSLER)
waste = 500;
if(fractype==LLORENZ)
projection = 1;
initorbitlong[0] = fudge; /* initial conditions */
initorbitlong[1] = fudge;
initorbitlong[2] = fudge;
if(fractype==LHENON)
{
l_a = param[0]*fudge;
l_b = param[1]*fudge;
l_c = param[2]*fudge;
l_d = param[3]*fudge;
}
else if(fractype==KAM || fractype==KAM3D)
{
a = param[0]; /* angle */
if(param[1] <= 0.0)
param[1] = .01;
l_b = param[1]*fudge; /* stepsize */
l_c = param[2]*fudge; /* stop */
t = l_d = param[3]; /* points per orbit */
l_sinx = sin(a)*fudge;
l_cosx = cos(a)*fudge;
l_orbit = 0;
initorbitlong[0] = initorbitlong[1] = initorbitlong[2] = 0;
}
else
{
l_dt = param[0]*fudge;
l_a = param[1]*fudge;
l_b = param[2]*fudge;
l_c = param[3]*fudge;
}
/* precalculations for speed */
l_adt = multiply(l_a,l_dt,bitshift);
l_bdt = multiply(l_b,l_dt,bitshift);
l_cdt = multiply(l_c,l_dt,bitshift);
return(1);
}
int orbit3dfloatsetup()
{
connect = 1;
waste = 100;
projection = 2;
if(fractype==FPHENON || fractype==FPPICKOVER || fractype==FPGINGERBREAD
|| fractype == KAMFP || fractype == KA